import React, { useEffect, useState } from "react";
import Add from "./Add";
import Update from "./Update";
import Search from "./Search";
import List from "./List";
import { Col, Row } from "antd";
import { find } from "../../services/student";
function Student(props) {
    const [students, setStudents] = useState([]);
    const [student, setStudent] = useState({});
    const [pagination,setPagination] = useState({
        showSizeChanger:true,
        showQuickJumper:true,
        pageSizeOptions:[5,10,15,20,25]
    });
    const [isUpdateOpen, setIsUpdateOpen] = useState(false);
    const [searchParams,setSearchParams] = useState({});
    const show = async (params = {}) => {
        if(params.type){
            setSearchParams(params);
        }else{
            params = {...searchParams,...params}
        }
        
        console.log("params",params)
        let data = await find(params);
        console.log("Data", data);
        setStudents(data.rows);
        data.current = parseInt(data.current);
        
        setPagination({...pagination,...data});
    };
    useEffect(() => {
        show();
    }, []);
    return (
        <div>
            <h2>学生管理</h2>
            <Row>
                <Col span={2}>
                    <Add show={show}></Add>
                </Col>
                <Col span={10}>
                    <Search show={show}></Search>
                </Col>
            </Row>

            <Update
                show={show}
                student={student}
                isUpdateOpen={isUpdateOpen}
                setStudent={setStudent}
                setIsUpdateOpen={setIsUpdateOpen}
            ></Update>
            <List
                show={show}
                setStudent={setStudent}
                students={students}
                pagination={pagination}
                setIsUpdateOpen={setIsUpdateOpen}
            ></List>
        </div>
    );
}
export default Student;
